package cn.amaake.magicplugin.nacos.util;

import cn.amaake.magicplugin.nacos.config.NacosConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.ConfigurableEnvironment;

public class NacosConfigPropertiesUtils {

    private static final Logger logger = LoggerFactory.getLogger(NacosConfigPropertiesUtils.class);

    public static NacosConfig buildNacosConfigProperties(ConfigurableEnvironment environment) {
        NacosConfig nacosConfigProperties = new NacosConfig();
        Binder binder = Binder.get(environment);
        ResolvableType type = ResolvableType.forClass(NacosConfig.class);
        Bindable<?> target = Bindable.of(type).withExistingValue(nacosConfigProperties);
        binder.bind("magic-api.nacos", target);
        logger.info("nacosConfigProperties : {}", nacosConfigProperties);
        return nacosConfigProperties;
    }

}
